﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace BaseSyntax.GenericTest
{
	public class ShortList<T>:IList<T>
	{
		protected IList<T> innerCollection;
		protected int maxSize = 10;

		public ShortList(int count)
		{
			maxSize = count;
			innerCollection = new List<T>();
		}

		public ShortList(int count, IEnumerable<T> list)
		{
			maxSize = count;
			innerCollection = new List<T>(list);

			if (count > 10)
			{
				throwException();
			}
		}
		
		public ShortList():this(10) {}


		public void throwException()
		{
			throw new IndexOutOfRangeException("lei hao a");
		}

		public IEnumerator<T> GetEnumerator()
		{
			return innerCollection.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public void Add(T item)
		{
			innerCollection.Add(item);
		}

		public void Clear()
		{
			innerCollection.Clear();
		}

		public bool Contains(T item)
		{
			return innerCollection.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			innerCollection.CopyTo(array, arrayIndex);
		}

		public bool Remove(T item)
		{
			return innerCollection.Remove(item);
		}

		public int Count
		{
			get => innerCollection.Count;
		}
		public bool IsReadOnly
		{
			get => innerCollection.IsReadOnly;
		}
		
		public int IndexOf(T item)
		{
			return innerCollection.IndexOf(item);
		}

		public void Insert(int index, T item)
		{
			innerCollection.Insert(index, item);
		}

		public void RemoveAt(int index)
		{
			innerCollection.RemoveAt(index);
		}

		public T this[int index]
		{
			get => innerCollection[index];
			set => innerCollection[index] = value;
		}
	}
}